package p.ithorns.integration.hazelcast.mqtt;


import p.ithorns.framework.core.model.IType;

import java.util.Arrays;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * @Author: liuhaitao
 * @Date: 2022/8/18 10:06
 * @Description: 主消息类型
 */
public enum UpMsgType implements IType<Integer> {

    // NONE
    NONE(0, "none", IType.class),

    // 定位数据
    LOCATE(1, "locate_data", LocateType.class);

    private final static Map<Integer, UpMsgType> MAP = Arrays.stream(UpMsgType.values())
            .collect(Collectors.toMap(UpMsgType::getCode, v -> v, (v1, v2) -> v2));


    UpMsgType(int code, String desc, Class<? extends IType> type) {
        init(code, desc, type);
    }


    public static UpMsgType of(Integer code) {
        if (Objects.isNull(code)) {
            return NONE;
        }
        return Optional
                .ofNullable(MAP.get(code))
                .orElse(NONE);
    }

}
